{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "4132510c",
   "metadata": {},
   "outputs": [],
   "source": [
    "#项目7-例7-4代码\n",
    "#数据准备\n",
    "from sklearn.datasets import load_breast_cancer #导入肺癌数据集\n",
    "from sklearn.svm import SVC     #导入支持向量机分类模块\n",
    "from sklearn.model_selection import train_test_split\n",
    "import numpy as np\n",
    "#import pandas as pd\n",
    "from sklearn.preprocessing import StandardScaler\n",
    "\n",
    "x,y=load_breast_cancer().data,load_breast_cancer().target \n",
    "x=StandardScaler().fit_transform(x)#数据标准化处理"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "8d3f5773",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXoAAAD4CAYAAADiry33AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAc0UlEQVR4nO3df3Dc9Z3f8edbvy3JtrQrYcCyLa3jSzDmZ4RZTa655EIy0HaOXjq9gU6HKxOGMHdkuL9ylM60d9fpDNPp5Y4/6DHkLndJkztK70JLU3oJk5aSpBJYBhswmMSWDRYG25JsC0m2ZEnv/rHfr7OWV9JK2vXufvb1mNFY+/1+V3p/+aKXPnrv5/tZc3dERCRcNaUuQEREiktBLyISOAW9iEjgFPQiIoFT0IuIBK6u1AXk0tHR4d3d3aUuQ0SkYuzdu3fE3Ttz7SvLoO/u7mZwcLDUZYiIVAwze2+xfWrdiIgETkEvIhI4Bb2ISOAU9CIigVPQi4gETkEvIhI4Bb2ISOCqOuiHT0/x4tsnSl2GiEhRVXXQ/8mLv+B3vreX+XmtyS8i4arqoB8YGuXCnHP23IVSlyIiUjRVG/THxqb44Mw5AEYnp0tcjYhI8VRt0PcPjV78fHRipoSViIgUV9UG/UBW0I9NKuhFJFxVGfTuzsDhUXq3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A4fcfcjdZ4BngLtLXFNVcveXgbEFm+8Gvh19/m0yP5hlb5FzqTju/qG7vxZ9/jHwDrCZCrwuS5xLxfGMiehhffThFOG6hBL0m4FjWY+HqdCLH3HgR2a218weLHUxBbDJ3T+EzA8qcFWJ61mrh83sjai1U/btjmxm1g3cArxChV+XBecCFXhdzKzWzPYBJ4EX3b0o1yWUoLcc2yq5J/UZd78VuAv43aiFIOXhz4DtwM3Ah8Afl7SaFTCzVuDvgN9z9/FS17MWOc6lIq+Lu8+5+81AF7DbzHYV4/uEEvTDwJasx13A8RLVsmbufjz69yTwHJnWVCU7EfVW4x7ryRLXs2rufiL64ZwHvkmFXJuoB/x3wPfc/fvR5oq8LrnOpVKvS8zdzwAvAXdShOsSStDvAXaYWY+ZNQD3AM+XuKZVMbOW6EUmzKwF+BLw1tLPKnvPA78dff7bwH8vYS1rEv8ARn6TCrg20Yt+fwG84+7fyNpVcddlsXOp0OvSaWZt0efrgDuAgxThugQx6wYgmk71p0At8C13//elrWh1zCxFZhQPUAf8dSWdi5n9DfA5MsutngD+LfDfgGeBrcD7wD9z97J/kXORc/kcmfaAA0eBr8b91HJlZr8K/AR4E5iPNj9GprddUddliXO5l8q7LjeSebG1lsyg+1l3/yMzS1Lg6xJM0IuISG6htG5ERGQRCnoRkcAp6EVEAqegFxEJnIJeRCRwCnoRkcAp6EVEAvf/ASEV7U7BB6csAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "模型的最优C值为：1.2340816326530613\n",
      "模型选取该参数时的预测准确率为：0.976608\n"
     ]
    }
   ],
   "source": [
    "#调节线性核函数的C值\n",
    "from sklearn.metrics import accuracy_score\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "#分割数据集\n",
    "x_train,x_test,y_train,y_test=train_test_split(x,y,test_size=0.3,random_state=420)\n",
    "\n",
    "score=[]\n",
    "C_range=np.linspace(0.01,30,50)\n",
    "for i in C_range:\n",
    "    model=SVC(kernel='linear',C=i)\n",
    "    model.fit(x_train,y_train)\n",
    "    pred=model.predict(x_test)\n",
    "    ac=accuracy_score(y_test,pred)\n",
    "    score.append(ac)\n",
    "#画曲线图，横轴为C值，纵轴为对应模型的预测准确率\n",
    "plt.plot(C_range,score)\n",
    "plt.show()\n",
    "#输出模型的最大预测准确率与对应的C值\n",
    "print(\"模型的最优C值为：%s\"%C_range[score.index(max(score))])\n",
    "print(\"模型选取该参数时的预测准确率为：%f\"%max(score))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "4223072e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXoAAAD7CAYAAABkO19ZAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAZ8klEQVR4nO3df5Cd1X3f8fdHq19GCCRbCwFJgADFoBJLJhuZFscWgyHCM4yCO3altIOjsSvToNTtH65Vp52kzXTGU+Ik7SBHVR0FOwPWpAMK8lRBuDE/3Ay2tbIF+gEyiwBpWUCrygYjc6/uj2//uM9Kl6u7u4927+pqz/28ZnZ2n+c5Z+85ftBnj8899zmKCMzMLF1T2t0AMzObWA56M7PEOejNzBLnoDczS5yD3swscQ56M7PEjRr0krZIOipp3zDXJem/S+qT9JykG+uurZR0MLu2oZUNNzOzfPKM6B8AVo5w/Q5gcfa1DvgLAEldwMbs+hJgjaQl42msmZmdvamjFYiIpyVdNUKRVcC3ovbJqx9ImiPpMuAqoC8iDgFI2pqVPTDaa86bNy+uumqklzQzs3q7d+8+FhHdza6NGvQ5zAeO1B33Z+eanf/IcL9E0jpq/4+AK664gt7e3hY0zcysM0h6dbhrrXgzVk3OxQjnm4qIzRHRExE93d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ZkHQZcFlE/FjSbGA38NvA7zLJ7ssIffkMk+++CJgVEe9Imgb8X+CLwKdo8X1JZUS/HOiLiEMRcRLYCqxqc5s6UkQ8DRxvOL0K+Gb28zep/cM87w3Tl0knIl6PiB9nP/8CeB6YzyS8LyP0ZdKJmneyw2nZVzAB9yWVoJ8PHKk77meS3vxMAI9L2i1pXbsb0wKXRsTrUPuHClzS5vaM13pJz2VTO+f9dEc9SVcBHwZ+yCS/Lw19gUl4XyR1SdoDHAW+GxETcl9SCXo1OTeZ56RujogbgTuAe7MpBDs//AVwDbAMeB34WltbcxYkXQg8DPybiHi73e0ZjyZ9mZT3JSIqEbEMWAAsl3TDRLxOKkHfDyysO14ADLSpLeMWEQPZ96PANmpTU5PZm9nc6tAc69E2t2fMIuLN7B9nFfifTJJ7k80BPww8GBGPZKcn5X1p1pfJel+GRMTPgSeBlUzAfUkl6HcBiyUtkjQdWA1sb3ObxkTSrOxNJiTNAm4H9o1c67y3Hfhs9vNngUfb2JZxGfoHmLmLSXBvsjf9/hJ4PiL+tO7SpLsvw/Vlkt6Xbklzsp/fB3wCeIEJuC9JrLoByJZT/TnQBWyJiP/S3haNjaSrqY3iAaYCD02mvkj6NrCC2uNW3wT+EPhb4G+AK4DDwKcj4rx/k3OYvqygNj0QwCvAF4bmU89Xkj4KfB/YC1Sz01+hNrc9qe7LCH1Zw+S7Lx+i9mZrF7VB999ExH+W9AFafF+SCXozM2sulakbMzMbhoPezCxxDnozs8Q56M3MEuegNzNLnIPezCxxDnozs8T9f7gdyoZeZexdAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "模型的最优C值为：6.7424489795918365\n",
      "模型选取该参数时的预测准确率为：0.982456\n"
     ]
    }
   ],
   "source": [
    "#调节高斯径向基核函数的C值\n",
    "from sklearn.metrics import accuracy_score\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "#分割数据集\n",
    "x_train,x_test,y_train,y_test=train_test_split(x,y,test_size=0.3,random_state=420)\n",
    "\n",
    "score=[]\n",
    "C_range=np.linspace(0.01,30,50)\n",
    "for i in C_range:\n",
    "    model=SVC(kernel='rbf',C=i,gamma=0.01207)\n",
    "    model.fit(x_train,y_train)\n",
    "    pred=model.predict(x_test)\n",
    "    ac=accuracy_score(y_test,pred)\n",
    "    score.append(ac)\n",
    "#画曲线图，横轴为C值，纵轴为对应模型的预测准确率\n",
    "plt.plot(C_range,score)\n",
    "plt.show()\n",
    "#输出模型的最大预测准确率与对应的C值\n",
    "print(\"模型的最优C值为：%s\"%C_range[score.index(max(score))])\n",
    "print(\"模型选取该参数时的预测准确率为：%f\"%max(score))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9626a679",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
